package org.hyl.javabase.socket;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;
import java.util.HashMap;

public class fclient {
	
	

	public static final int PORT = 12345;// �������˿ں�
	//static String path = System.getProperty("user.dir") + "/src/javabase/p201707017/cclient.java";

	public static void main(String[] args) {
	    HashMap<String,String> hmaddr=new HashMap<>();
		hmaddr.put("����","192.168.10.69");
		hmaddr.put("־��","192.168.10.162");
		hmaddr.put("··","192.168.10.185");
		hmaddr.put("����","192.168.10.59");
		hmaddr.put("־��","192.168.10.70");
		hmaddr.put("����","192.168.10.238");
		String path="d:/myBase_1.nyf";
		System.out.println("�ͻ�������...");
		FileInputStream fs =null;
		Socket socket = null;
		try {
			// ����һ�����׽��ֲ��������ӵ�ָ�������ϵ�ָ���˿ں�
			socket = new Socket(hmaddr.get("··"), PORT);
			File f = new File(path);
			fs=new FileInputStream(f);
			byte[] buf = new byte[8000];
			DataOutputStream out = new DataOutputStream(socket.getOutputStream());
			int len = 0;
			System.out.println("��ʼ���䡣����");
			while ((len = fs.read(buf)) != -1) {
				out.write(buf,0,len);				
				System.out.println("len="+len+" buf="+buf.length);
			}
			System.out.println("���ʼ���䡣����");
			out.flush();
			out.close();
			System.out.println("�Ѿ��������");
			// input.close();
		} catch (Exception e) {
			System.out.println("�ͻ����쳣:" + e.getMessage());
		} finally {
			if (socket != null) {
				try {
					socket.close();
				} catch (IOException e) {
					socket = null;
					System.out.println("�ͻ��� finally �쳣:" + e.getMessage());
				}
			}
			if (fs != null) {
				try {
					fs.close();
				} catch (Exception e) {
					fs = null;				
				}
			}
		}

	}
}
